using System;
using System.Windows;

namespace Intuipic
{
	/// <summary>
	/// Interaction logic for App.xaml
	/// </summary>

	public partial class App
	{
		protected override void OnStartup(StartupEventArgs e)
		{
			base.OnStartup(e);
			System.Threading.Thread.CurrentThread.Name = "UI";
			Resources["DelayConverter"] = new DelayConverter();
		}

		//converts between a TimeSpan and number of milliseconds
		private sealed class DelayConverter : System.Windows.Data.IValueConverter
		{
			public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
			{
				if (value is TimeSpan)
				{
					return ((TimeSpan) value).TotalMilliseconds / 1000;
				}

				return DependencyProperty.UnsetValue;
			}

			public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
			{
				if (value is double)
				{
					return new TimeSpan(0, 0, 0, 0, (int) ((double) value * 1000));
				}

				return DependencyProperty.UnsetValue;
			}
		}
	}
}